<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>IOS签包 - 登录</title>

    <link rel="shortcut icon" href="${ctxPath}/static/favicon.ico">
    <link href="${ctxPath}/static/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxPath}/static/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${ctxPath}/static/css/style.css?v=4.1.0" rel="stylesheet">
    <script>if (window.top !== window.self) {
        window.top.location = window.location;
    }</script>
    <script src="${ctxPath}/static/js/jquery.min.js?v=2.1.4"></script>
    <script src="${ctxPath}/static/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="${ctxPath}/static/js/plugins/layer/layer.js"></script>
    <script src="${ctxPath}/static/layui/layui.js"></script>
    <script src="${ctxPath}/static/js/common/Feng.js"></script>
</head>

<body class="gray-bg">

<div class="middle-box text-center loginscreen">
    <div style="padding: 100px 0px;">
        <div>
            <h1 class="logo-name">IOS签包</h1>
        </div>
        <h3>欢迎使用 IOS签名后台管理</h3>
        <br/>
        <h4 style="color: red;">${tips!}</h4>
        <form id="login" class="m-t" role="form" action="${ctxPath}/login" method="post">
            <div>
                <div class="form-group">
                    <input type="text" id="username" name="username" class="form-control" placeholder="用户名" required="">
                </div>
                <div class="form-group">
                    <input type="password" id="password" name="password" class="form-control" placeholder="密码" required="">
                </div>
                <div class="form-group" style="float: left;">
                    <div class="checkbox" style="text-align: left">
                        <label>
                            <input type="checkbox" name="remember" style="margin-top: 2px;">记住我
                        </label>
                    </div>
                </div>
                <button type="submit" class="btn btn-primary block full-width m-b">登 录</button>
                <div style="display: flex;flex-direction: row;align-items: center;justify-content: center">
                    <lable style="font-size: 14px;">没有账号?</lable>
                    <a onclick="goRegister()" style="color: #2d8ffd;font-size: 16px;">去注册</a>
                </div>
            </div>
        </form>

        <div id="register" style="display: none;">
            <div class="form-group">
                <input type="text" id="registerName" class="form-control" placeholder="请输入账号" required="">
            </div>
            <div class="form-group">
                <input type="password" id="password1" class="form-control" placeholder="设置登录密码" required="">
            </div>
            <div class="form-group">
                <input type="password" id="password2" class="form-control" placeholder="确认密码" required="">
            </div>
            <button class="btn btn-primary block full-width m-b" onclick="register()">注 册</button>
            <div style="display: flex;flex-direction: row;align-items: center;justify-content: center">
                <lable style="font-size: 14px;">已有账号</lable>
                <a onclick="goLogin()" style="color: #2d8ffd;font-size: 16px;">去登录</a>
            </div>
        </div>
    </div>
</div>

<script>
    Feng.addCtx("${ctxPath}");
    Feng.sessionTimeoutRegistry();
    function goRegister() {
        $("#register").show();
        $("#login").hide();
        $("#registerName").val("");
        $("#password1").val("");
        $("#password2").val("");
    }
    function goLogin() {
        $("#register").hide();
        $("#login").show();
        $("#username").val("");
        $("#password").val("");
    }

    function register() {
        var userName = $("#registerName").val();
        var pwd1 = $("#password1").val();
        var pwd2 = $("#password2").val();
        if (userName == null || userName == ""){
            Feng.error("登录账号不能为空")
        }else if (pwd1 == null || pwd1 == ""){
            Feng.error("请设置登录密码")
        }else if (pwd1 != pwd2){
            Feng.error("两次密码不一致")
        }else {
            var queryData = {};
            queryData['userName'] = userName;
            queryData['password'] = pwd1;
            $.ajax({
                url: Feng.ctxPath + "/register",
                dataType:'json',
                type:'POST',
                async: false,
                data: JSON.stringify(queryData),
                processData : false, // 使数据不做处理
                contentType : 'application/json', // 不要设置Content-Type请求头
                success: function(data){
                    Feng.success("注册成功，请用新账号登录")
                    goLogin();
                },
                error:function(response){
                    Feng.error(response.responseJSON.message);
                }
            });
        }
    }
</script>

</body>

</html>
